home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / ndp.zip / NDP_TYPE.ASM next >
Assembly Source File  |  1987-08-01  |  4KB  |  98 lines

  1. page    60,132
  2. title   ndp_type() - Math Coprocessor Check
  3.  
  4. ; ndp_type -   Check for Math Coprocessor -
  5. ;                  Report Presence and Type....
  6. ;
  7. ;   calling convention:
  8. ;
  9. ;       int ndp_type( void );
  10. ;
  11. ;   returns:
  12. ;
  13. ;       you get back  0 if NO CHIP is found
  14. ;                     1 if an 8087 is found
  15. ;                     2 if an 80287
  16. ;             and     3 for an 80387
  17. ;
  18. ;
  19. ;       FREELY adopted from Ted Forgeron's
  20. ;              article and code in PC Tech
  21. ;              Journal, Aug 87 p 43  /Psi!
  22.  
  23. _text   SEGMENT BYTE PUBLIC 'CODE'
  24.         ASSUME  CS:_text
  25.  
  26.         PUBLIC  _ndp_type
  27.  
  28. _ndp_type      PROC NEAR
  29.  
  30. control dw     0
  31.  
  32.         push   BP                       ; save where Ur at when
  33.         mov    BP,SP                    ;  going in.....
  34.         push   DI
  35.         push   SI
  36.         push   CX                       ; not really needed for
  37.                                         ;   MSC but nice to do
  38.  
  39. ; Check for an NDP.  Don't forget to assemble with the /R option
  40. ; set in MASM or you'll bomb cuz of the coprocessor instructions.
  41.  
  42. do_we:  fninit                          ; try to initialize NDP
  43.         mov    byte ptr control+1,0     ; clear memory byte
  44.         fnstcw control                  ; put control word in mem
  45.         mov    AH,byte ptr control+1    ; iff AH is 03h, you got
  46.         cmp    AH,03h                   ;     an NDP on board !!
  47.         je     chk_87                   ; found somethin', keep goin'
  48.         xor    AX,AX                    ; clean out AX to show a zero
  49.         jmp    short byebye             ;   return [no NDP]
  50.  
  51. ; 'got an 8087 ??
  52.  
  53. chk_87: and    control,NOT 0080h        ; turn ON interrupts (IEM=0)
  54.         fldcw  control                  ; load control word
  55.         fdisi                           ; turn OFF interrupts (IEM=1)
  56.         fstcw  control                  ; store control word
  57.         test   control,0080h            ; iff IEM=1, 8087
  58.         jz     chk287                   ; 'guess not!  March on....
  59.         mov    AX,0001                  ; set up for a 1 return to
  60.         jmp    short byebye             ;   show an 8087
  61.  
  62. ; if not.... would you believe an 80287 maybe ??
  63.  
  64. chk287: finit                           ; set default infinity mode
  65.         fld1                            ; make infinity
  66.         fldz                            ;     by dividing
  67.         fdiv                            ;         1 by zero !!
  68.         fld    st                       ; now make a
  69.         fchs                            ;     negative infinity
  70.         fcompp                          ; compare Ur two infinities
  71.         fstsw  control                  ; iff, for 8087 or 80287
  72.         fwait                           ; 'til status word is put away
  73.         mov    AX,control               ; getchur control word
  74.         sahf                            ; putchur AH into flags
  75.         jnz    got387                   ; NO GOOD.... march on !!
  76.         mov    AX,0002                  ; gotta be a 80287 cuz we al-
  77.         jmp    short byebye             ;   ready tested for an 8087
  78.  
  79. ; We KNOW that there is an NDP on board otherwise we would have bailed
  80. ; out after 'do_we'.  It isn't an 8087 or an 80287 or we wouldn't have
  81. ; gotten this far.  It's gotta be an 80387 !!
  82.  
  83. got387: mov    AX,0003                  ; it isn't an 8087 or an 80287
  84.                                         ; but we do know it is an NDP
  85.                                         ; so let's call it an 80387
  86.                                         ; and return a 3
  87.  
  88. byebye: pop    CX                       ; put things back the way that
  89.         pop    SI                       ; you found 'em
  90.         pop    DI
  91.         pop    BP
  92.         ret                             ; and go back where you came
  93.                                         ; from
  94. _ndp_type      endp
  95.  
  96. _text   ends
  97.         end
  98.